﻿using Inaction;
using Inaction.ServiceContract;
using Inaction.Mapping;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Security.Principal;

namespace Inaction.Security
{
    [Serializable]
    public abstract class Principal : IPrincipal
    {
        #region 属性
        [ThreadStatic]
        static Principal instance;
        public static Principal Instance
        {
            get { return instance; }
            set { instance = value; }
        }
        public IIdentity Identity { get; protected set; }

        System.Security.Principal.IIdentity IPrincipal.Identity
        {
            get { return Identity; }
        }


        #endregion

        #region 方法

        #region abstract
        public abstract bool IsInRole(string role);
        public abstract IEnumerable<IRole> GetOwnedRoles();
        #endregion

        #region static
        public static string ChangePassword(string userNumber, string password, string newPassword)
        {
            return ServiceContainer.GetService<ISecurityProvider>().ChangePassword(userNumber, password, newPassword);
        }
        #endregion
        #endregion
    }
}